<?php

namespace app\common\model\banxi\learn;

use app\common\enums\say\LearnSayQuestionAnswerRecordEnum;
use app\common\model\banxi\student\Student;
use app\common\model\banxi\trainer\Trainer;
use app\common\model\common\BaseModel;
use think\model\concern\SoftDelete;

/**
 * 全科习题答题记录
 */
class LearnSayQuestionAnswerRecord extends BaseModel
{
    use SoftDelete;

    protected $name = 'banxi_learn_say_question_answer_record';

    protected $autoWriteTimestamp = true;

    protected $deleteTime = 'del';

    protected $defaultSoftDelete = 0;

    protected $append = [
        'splitSentenceList',
        'sentenceWordColorList',
        'intonationGroupList',
        'coreVocabularyList',
        'expandVocabularyList',
        'isCorrectCn',
        'translationCorrectCn',
        'questionCorrectCn'
    ];

    protected $type = [
        'id' => 'string',
        'del' => 'string',
        'sayTeachSentenceId' => 'string',
        'recordId' => 'string',
        'studentId' => 'string',
        'trainerId' => 'string',
        'isCorrect' => 'string',
        'createTime' => 'timestamp:Y-m-d H:i:s',
        'updateTime' => 'timestamp:Y-m-d H:i:s',
    ];
    //-----------------------------------------------------------------------------------
    //｜                                   获取器                                       ｜
    //-----------------------------------------------------------------------------------

    public function getSplitSentenceListAttr($value, $data)
    {
        return isset($data['splitSentence']) ? json_decode($data['splitSentence'], true) : [];
    }

    public function getSentenceWordColorListAttr($value, $data)
    {
        $value = $value ?: ($data['sentenceWordColor'] ?? '');
        return json_decode($value, true) ?? [];
    }

    public function getIntonationGroupListAttr($value, $data)
    {
        $value = $value ?: ($data['intonationGroup'] ?? '');
        return json_decode($value, true) ?? [];
    }

    public function getCoreVocabularyListAttr($value, $data)
    {
        $value = $value ?: ($data['coreVocabulary'] ?? '');
        return json_decode($value, true) ?? [];
    }

    public function getExpandVocabularyListAttr($value, $data)
    {
        $value = $value ?: ($data['expandVocabulary'] ?? '');
        return json_decode($value, true) ?? [];
    }

    public function getIsCorrectCnAttr($value, $data)
    {
        $value = $value ?: ($data['isCorrect'] ?? '');
        return (new LearnSayQuestionAnswerRecordEnum())->getDescription($value) ?? '';
    }

    public function getTranslationCorrectCnAttr($value, $data)
    {
        $value = $value ?: ($data['translationCorrect'] ?? '');
        return (new LearnSayQuestionAnswerRecordEnum())->getDescription($value) ?? '';
    }

    public function getQuestionCorrectCnAttr($value, $data)
    {
        $value = $value ?: ($data['questionCorrect'] ?? '');
        return (new LearnSayQuestionAnswerRecordEnum())->getDescription($value) ?? '';
    }
    //-----------------------------------------------------------------------------------
    //｜                                   处理方法                                       ｜
    //-----------------------------------------------------------------------------------

    //-----------------------------------------------------------------------------------
    //｜                                   模型关联                                       ｜
    //-----------------------------------------------------------------------------------

    public function student()
    {
        return $this->hasOne(Student::class, 'id', 'studentId');
    }

    public function trainer()
    {
        return $this->hasOne(Trainer::class, 'id', 'trainerId');
    }
}